﻿using IOP.Models.Message.MQTT;
using IOP.Models.Message.MQTT.Package;
using IOP.Pulsar.MQTT;
using IOP.Pulsar.MQTT.Attributes;
using IOP.Pulsar.MQTT.Result;
using Microsoft.Extensions.Logging;
using System.Text;

namespace UAVDemo.Server
{
    public class UAVController : MQTTController
    {
        private readonly ILogger<UAVController> _Logger;

        public UAVController(ILogger<UAVController> logger)
        {
            _Logger = logger;
        }

        [CONNECT]
        public ConnectResult ConnectTest(ConnectPackage package)
        {
            _Logger.LogInformation($"{Context.Session.ClientId} connect");
            return Connack(ReturnCodeType.Accept);
        }

        [PUBLISH("/uav")]
        public PublishResult UAVPublish(PublishPackage package)
        {
            return PublishFinish();
        }

        [SUBSCRIBE]
        public SubscribeResult UAVSubscribe(SubscribePackage package)
        {
            _Logger.LogInformation($"{Context.Session.ClientId} subscribe topic : /uav");
            return Suback();
        }

        [PINGREQ]
        public PingreqResult UAVPingreq(PingreqPackage package)
        {
            _Logger.LogInformation($"{Context.Session.ClientId} keep alive");
            return Pingresp();
        }
    }
}
